package ofpof.service;

import ofpof.domain.dao.UserDao;
import ofpof.service.mail.EmailCommand;
import ofpof.service.mail.EmailService;
import ofpof.web.form.UserForm;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
	
	@Autowired
	private UserDao userDao;
	
	@Autowired
	private EmailService emailService;
	
	
	public void createNewUser(UserForm userForm) {
		userDao.create(userForm.getUser());
		
		EmailCommand emailCommand = new EmailCommand();
		emailCommand.addObject("user", userForm.getUser());
		emailCommand.setTemplate("emailyouruseriscreated.vm");
		emailCommand.setTo(userForm.getUser().getEmail());
		
		emailService.sendEmail(emailCommand);
	}

}
